package com.fowo.api.datainterface.model;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fowo.api.datainterface.entity.Datainterface;
import com.fowo.api.datainterface.entity.DatainterfaceAuthority;
import com.fowo.api.datainterface.entity.DatainterfaceMapping;
import com.fowo.api.datainterface.entity.DatainterfaceTask;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;
import java.util.List;
import java.util.Map;


@Getter
@Setter
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@Schema(title = "事务上下文")
public class DataContextModel extends DatainterfaceTask implements Serializable {


    @Schema(title = "接口映射")
    private List<DatainterfaceMappingModel> mapping;

    @Schema(title = "源接口信息")
    private List<DatainterfaceFromModel> from;

    @Schema(title = "目标接口信息")
    private List<DatainterfaceToModel> to;


    @Getter
    @Setter
    @Accessors(chain = true)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(title = "执行接口数据")
    public class DatainterfaceInvokeModel extends Datainterface {
        @Schema(title = "接口授权信息")
        private DatainterfaceAuthorityModel authority;
    }

    @Getter
    @Setter
    @Accessors(chain = true)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(title = "源接口数据")
    public class DatainterfaceFromModel extends DatainterfaceInvokeModel {

        @Schema(title = "任务编号")
        private String taskCode;

        @Schema(title = "接口数据")
        private Object data;

        @Schema(title = "接口映射信息")
        private List<DatainterfaceMappingModel> mapping;


    }

    @Getter
    @Setter
    @Accessors(chain = true)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @Schema(title = "目标口数据")
    public class DatainterfaceToModel extends DatainterfaceInvokeModel {
        @Schema(title = "任务编号")
        private String taskCode;
        @Schema(title = "接口映射信息")
        private List<DatainterfaceMappingModel> mapping;
        @Schema(title = "映射成功的数据")
        private Map<String, List<JSONObject>> mappingSuccessData;
        @Schema(title = "映射错误的数据")
        private Map<String, List<JSONObject>> mappingFailData;
        @Schema(title = "运行环境")
        private String environment;
        @Schema(title = "预览入参数据")
        private Map<String, List<JSONObject>> callJsData;


    }

    @Getter
    @Setter
    @Accessors(chain = true)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @Schema(title = "接口授权信息")
    public class DatainterfaceAuthorityModel extends DatainterfaceAuthority {
        @Schema(title = "其他授权数据")
        private JSONObject otherData;
    }

    @Getter
    @Setter
    @Accessors(chain = true)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @Schema(title = "接口映射信息")
    public class DatainterfaceMappingModel extends DatainterfaceMapping {
    }
}
